package cn.joeg.app.web.items.user;

import cn.joeg.app.css.util.CheckPhoneUtil;
import cn.joeg.app.web.core.def.AbstractWidgetAdapter;
import cn.joeg.app.web.core.vo.WidgetDataResp;
import cn.joeg.app.web.db.user.UserService;
import cn.joeg.app.web.util.Const;
import cn.joeg.app.web.util.Event;
import cn.joeg.app.web.util.GameUtil;
import com.ecfront.dew.common.Resp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 *
 */
@Component("user")
public class WidgetAdapter extends AbstractWidgetAdapter {

    private static final String WIDGET_CODE = "user";

    private static final Logger logger = LoggerFactory.getLogger(WidgetAdapter.class);


    @Autowired
    UserService userService;


    @Override
    public String getCode() {
        return WIDGET_CODE;
    }

    /**
     * @param req
     * @return
     */
    public Resp<WidgetDataResp> queryDeviceByAccount(WidgetReqVO req) {

        System.out.println("");
        return Resp.success(WidgetDataResp.build(new String()));

    }
/*

    public Resp<WidgetDataResp> setPhonePassword(WidgetReqVO req) {

        String id = req.getId();
        String phoneNum = req.getPhoneNum() == null ? "" : req.getPhoneNum().trim();
        String password = req.getPassword() == null ? "" : req.getPassword().trim();
        String model = req.getModel();
        String type = req.getType();
        String ver = req.getVer();
        //校验 略

        if (CheckPhoneUtil.isPhoneNum(phoneNum) && password.length() > 0 && !password.contains(" ")) {


            List<UserService.UserVO> list = userService.queryUserByPhoneNum(phoneNum);
            if (list.size() > 0) {
                return Resp.customFail("1", "已有该用户");
            } else {

                UserService.UserVO userVO = userService.queryUserById("id, phonenum,password", id);
                if (userVO != null) {
                    if (userVO.getPhonenum().length() == 0) {

                        boolean b = userService.updatePhoneNum(userVO.getId(), phoneNum, password);
                        if (b) {
                            initValue(userVO);
                        }
                        Event.addGiftEvent(id + "", Message.M1073, 10, 100000, 50, 0, -1, 0, 0, 0, 0);
                        return 0;
                    } else {
                        return Resp.customFail("1", );
                    }


                }


//                EventRunnable

            }


        }


        return null;
    }

    private void initValue(UserService.UserVO userVO) {

        long hasDiamond = userVO.getHasdiamond();
        int vip = GameUtil.getVipLevel(hasDiamond);
        int userVip = userVO.getUservip();

        if (vip > userVip) {
            if (vip == 6) {

                Event.addGiftEvent(mId + "", "VIP", 10, 0, 0, 0, -1, 0, 1008, 1, 0);
            }
            userVip = vip;
            DBCommon.executeUpdate("update starwork_user set uservip=" + mVip + " where id=" + mId);
        }

        setMaxCardNum();

        // System.out.println(mCompanyName+"数据保存竞技次数："+mArenaCount);
        OnlineUserCache.set(JedisPrefix.USER_ + mId, this);


    }

*/

}
